package com.nhh.v.aop;

import com.nhh.v.dto.RequiredRequestHeader;
import com.nhh.v.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * Created by ywp on 2018/9/3.
 */
@Slf4j
@Aspect
@Component
public class UidCheckAspect {


    @Pointcut("within(@org.springframework.web.bind.annotation.RestController *)")
    public void pointcut() {
    }

    @Before(value = "pointcut()")
    public void checkUid(JoinPoint joinPoint) throws Throwable {
        Object[] joinPointArgs = joinPoint.getArgs();
        if (Objects.nonNull(joinPointArgs) && joinPointArgs.length != 0) {
            Object firstArg = joinPointArgs[0];
            if (firstArg instanceof RequiredRequestHeader) {
                RequiredRequestHeader header = (RequiredRequestHeader) joinPointArgs[0];
            }

            //todo 微信登陆验证

            log.info(JsonUtil.toJsonString(joinPointArgs));
        }

    }


}
